Skip to content

Guarded _tx_thread_stack_analyze against inverted stack pointers - #727

Merged
fdesbiens merged 1 commit into
eclipse-threadx:devfrom
fdesbiens:fix/issue-460
Sep 15, 2026
Merged

fdesbiens merged 1 commit into
eclipse-threadx:devfrom
fdesbiens:fix/issue-460

Conversation

@fdesbiens

@fdesbiens fdesbiens commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #460

TX_ULONG_POINTER_DIF casts the pointer difference to ULONG, so when
tx_thread_stack_highest_ptr sits below tx_thread_stack_start the midpoint
wraps to a huge value, the probe lands outside the stack, and the search never
converges: the caller hangs or faults.

_tx_thread_stack_analyze now requires the highest pointer to be strictly above
the start of the stack, and bounds the final scan by it. #464 covered the
TX_THREAD_STACK_CHECK path; this covers direct callers too, as
@billlamiework suggested on the issue.

Inconsistent pointers still mean a real overflow or a corrupted control block,
which remains the application's problem. What changes is that ThreadX reports it
through the stack error handler instead of hanging.

New cases for an inverted and an equal pointer pair crash the suite without the
fix and pass with it.

…er that is not above the start of the stack, so a stack overflow or a corrupted control block no longer hangs or crashes the caller

_tx_thread_stack_analyze computed the midpoint of the remaining stack with
TX_ULONG_POINTER_DIF, which casts the pointer difference to ULONG. When
tx_thread_stack_highest_ptr had already moved below tx_thread_stack_start,
the difference was negative and wrapped to a huge unsigned value, so the
binary search probed far outside the stack and never converged.

The highest stack pointer is now required to be above the start of the
stack before the search begins, and the final scan for the first used word
is bounded by the initial highest stack pointer so it cannot run past the
end of the region either.

Added regression coverage for an inverted and for an equal pair of stack
pointers. Without the fix the new test case crashes the suite.

Assisted-by: Copilot (Opus 5) <noreply@github.com>
@fdesbiens fdesbiens changed the title Guarded the stack analyze binary search against a highest stack pointer that is not above the start of the stack, so a stack overflow or a corrupted control block no longer hangs or crashes the caller Guarded _tx_thread_stack_analyze against inverted stack pointers Sep 15, 2026
@fdesbiens
fdesbiens merged commit 1d4a4ae into eclipse-threadx:dev Sep 15, 2026
19 checks passed
@fdesbiens
fdesbiens deleted the fix/issue-460 branch September 16, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant